package com.pangus.toolkits.files.operation;

import com.pangus.toolkits.files.FSContext;
import com.pangus.toolkits.files.constants.ApiUrl;
import com.pangus.toolkits.files.http.NetworkClient;
import com.pangus.toolkits.files.http.Response;
import com.pangus.toolkits.files.result.StorageInfo;
import okhttp3.HttpUrl;
import okhttp3.Request;

import java.io.IOException;

/**
 * @author yingheng chen
 * @description
 * @date 2019/11/30
 */
public class FSSystemOperation extends BaseOperation{
    private final NetworkClient httpClient;
    private final HttpUrl baseUrl;

    public FSSystemOperation(NetworkClient httpClient, FSContext context) {
        super(context);
        this.httpClient = httpClient;
        this.baseUrl = context.getUrl();
    }


    public Response<StorageInfo> getStorageInfo() throws IOException {
        HttpUrl url = this.baseUrl.newBuilder()
                .addEncodedPathSegments(ApiUrl.GET_StorageInfo)
                .build();
        Request req = getBaseRequestBuilder()
                .url(url)
                .build();

        return httpClient.call(req, StorageInfo.class);
    }


}
